<template>
  <div class="container">
    <!-- 评星 -->
    <ul class="container_item">
      <li class="row">
        商品评星
        <span class="star_box">
          <img :src="goods_star>=1?'https://h5.ameimeika.com/mp_images/star/pingxing-liang@2x.png':'https://h5.ameimeika.com/mp_images/star/pingxing-hui@2x.png'"
               alt
               class="little_star"
               @click="change_goods_star(1)">
          <img :src="goods_star>=2?'https://h5.ameimeika.com/mp_images/star/pingxing-liang@2x.png':'https://h5.ameimeika.com/mp_images/star/pingxing-hui@2x.png'"
               alt
               class="little_star"
               @click="change_goods_star(2)">
          <img :src="goods_star>=3?'https://h5.ameimeika.com/mp_images/star/pingxing-liang@2x.png':'https://h5.ameimeika.com/mp_images/star/pingxing-hui@2x.png'"
               alt
               class="little_star"
               @click="change_goods_star(3)">
          <img :src="goods_star>=4?'https://h5.ameimeika.com/mp_images/star/pingxing-liang@2x.png':'https://h5.ameimeika.com/mp_images/star/pingxing-hui@2x.png'"
               alt
               class="little_star"
               @click="change_goods_star(4)">
          <img :src="goods_star>=5?'https://h5.ameimeika.com/mp_images/star/pingxing-liang@2x.png':'https://h5.ameimeika.com/mp_images/star/pingxing-hui@2x.png'"
               alt
               class="little_star"
               @click="change_goods_star(5)">
        </span>
      </li>
    </ul>
    <div class="evaluat">
      <div class="header">评论</div>
      <div class="content">
        <textarea v-if="showarea"
                  @blur="change_status(false)"
                  :fixed="true"
                  @input="changeeva()"
                  v-model="content"
                  maxlength="255"
                  class="textarea"
                  placeholder="请输入评论" />
        <div class="textarea" v-else @tap="change_status(true)">{{content}}</div>
        <div class="tip">{{max_length}}</div>
      </div>
    </div>
    <picupload :picture_num="9" v-on:getmsg="hasmsg"></picupload>
    <div class="btnbox">
      <button class="btn" @click="submitScoring" :disabled="isTrue">提交评价</button>
    </div>
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
import picupload from "@/components/pic_upload/pic_upload";
export default {
  data () {
    return {
      showarea: true,
      baseUrl: common.image_response,
      id: "",
      img_arr: [],
      tempFilePaths: [],
      content: "",
      isTrue: false,
      goods_star: 5,
      goods_id: "",
      order_id: "",
      max_length: 255
    };
  },
  onLoad (options) {
    Object.assign(this.$data, this.$options.data());
    wx.setNavigationBarTitle({
      title: "评价"
    });
    if (options.goods_id) {
      this.goods_id = options.goods_id;
      this.order_id = options.order_id;
    }
  },
  components: {
    picupload
  },
  methods: {
    change_status (status) {
      this.showarea = status;
    },
    hasmsg (msg) {
      this.img_arr = msg;
    },
    changeeva () {
      this.max_length = 255 - this.content.length;
    },
    // 提交评价
    submitScoring () {
      if (this.content.trim() == "") {
        wx.showToast({
          title: "请填写评论", //提示的内容,
          icon: "none", //图标,
          duration: 2000, //延迟时间,
          mask: true //显示透明蒙层，防止触摸穿透,
        });
        return false;
      } else if (255 - this.max_length < 15) {
        wx.showToast({
          title: "评价不能少于15字哦～", //提示的内容,
          icon: "none", //图标,
          duration: 1500, //延迟时间,
          mask: true, //显示透明蒙层，防止触摸穿透,
          success: res => { }
        });
        return false;
      } else {
        var reg;
        reg = /\S{15}/;
        if (!reg.test(this.content)) {
          wx.showToast({
            title: "评价不能少于15字哦~", //提示的内容,
            icon: "none", //图标,
            duration: 2000, //延迟时间,
            mask: true //显示透明蒙层，防止触摸穿透,
          });
          return false;
        }
        this.isTrue = true; //按钮禁用
        wx.showLoading({
          title: "提交中...", //提示的内容,
          mask: true //显示透明蒙层，防止触摸穿透,
        });
        common.fly_post(
          "api/v4_2/orders/comAdd",
          {
            order_id: this.order_id,
            good_id: this.goods_id,
            star: this.goods_star,
            images: this.img_arr.join(","),
            contents: this.content
          },
          response => {
            wx.hideLoading();
            let res = response.data;
            this.isTrue = false;
            if (res.status_code == 0) {
              //   wx.redirectTo({
              //     url: "/pages/package_mall/scor_success/main"
              //   });
              
              wx.redirectTo({ url: '/pages/package_mine/my_order/main?type=0' });
            } else {
              wx.hideLoading();
              wx.showToast({
                title: res.message,
                icon: "none",
                duration: 2000,
                mask: true
              });
              return false;
            }
          }
        );
      }
    },
    change_goods_star (num) {
      this.goods_star = num;
    }
  }
};
</script>

<style scoped lang="less">
.container {
  background: rgba(251, 251, 251, 1);
  padding-top: 10px;
  height: 100%;
  overflow: auto;
}
.container_item {
  width: 100%;
  height: 50px;
  box-sizing: border-box;
  padding: 15px;
  margin-bottom: 10px;
  background-color: #fff;
  .row {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    position: relative;
    .star_box {
      width: 150px;
      height: 20px;
      position: absolute;
      top: 0;
      right: 0;
      .little_star {
        width: 20px;
        height: 20px;
        margin-right: 2px;
        vertical-align: bottom;
      }
    }
  }
}
.evaluat {
  height: 180px;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 1px 0px 0px rgba(204, 204, 204, 0.5);
  margin-top: 10px;
  .header {
    line-height: 44px;
    padding-left: 15px;
    font-size: 14px;
    font-family: "PingFangSC-Regular";
    font-weight: 400;
    color: rgba(102, 102, 102, 1);
  }
  .content {
    width: 345px;
    height: 120px;
    background: rgba(251, 251, 251, 1);
    margin: 0 auto;
    position: relative;
    .textarea {
      width: 100%;
      height: 100%;
      background: rgba(251, 251, 251, 1);

      padding: 8px 10px;
      font-size: 14px;
      font-family: "PingFangSC-Regular";
      box-sizing: border-box;
    }
    .tip {
      font-size: 10px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(136, 136, 136, 1);
      position: absolute;
      bottom: 10px;
      right: 10px;
    }
  }
}
.image-uploader {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 1px 0px 0px rgba(204, 204, 204, 0.5);
  margin-top: 10px;
  padding-bottom: 20px;
  margin-bottom: 60px;
  .header {
    line-height: 44px;
    padding-left: 15px;
    font-size: 14px;
    font-family: "PingFangSC-Regular";
    font-weight: 400;
    color: rgba(102, 102, 102, 1);
    .tip {
      font-size: 12px;
      font-family: "PingFangSC-Regular";
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
    }
  }
  .image-list {
    margin-left: 15px;
    .image-item {
      width: 104px;
      height: 104px;
      border: 1px dashed rgba(204, 204, 204, 1);
      float: left;
      margin-right: 10px;
      margin-bottom: 10px;
      // overflow: hidden;
      position: relative;
      .image {
        width: 104px;
        height: 104px;
      }
      .del {
        width: 20px;
        height: 20px;
        background: rgba(255, 255, 255, 1);
        box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.49);
        border-radius: 50%;
        color: #888;
        position: absolute;
        right: -5%;
        top: -9%;
        font-size: 20px;
        line-height: 20px;
        text-align: center;
        z-index: 9999;
      }
      .icon {
        font-size: 26px;
        color: rgba(204, 204, 204, 1);
        text-align: center;
        margin-top: 18px;
      }
      .msg {
        text-align: center;
        font-size: 12px;
        margin-top: 10px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(204, 204, 204, 1);
      }
    }
  }
}
.btnbox {
  width: 100%;
  height: auto;
  border: none;
  margin-top: 40px;
  margin-bottom: 40px;
}
.btn {
  width: 100%;
  height: 50px;
  font-size: 17px;
  line-height: 50px;
  background: rgba(255, 56, 62, 1);
  color: #fff;
  position: absolute;
  bottom: 0;
  font-size: 17px;
  font-family: "Medium";
  font-weight: 500;
  color: rgba(255, 255, 255, 1);
}
.height1 {
  height: 218px;
}
.height2 {
  height: 332px;
}
.height3 {
  height: 446px;
}
</style>


